package ACM.shence;

/**
 * @Author wwk
 * @DATE 2022/8/26 19:56
 */
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class first {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String ip = sc.next();
            String[] split = ip.split("\\.");
            System.out.println(Arrays.toString(split));
            boolean flag = true;
            Long res = 0L;
            if(split.length!=7 ){
                //首末不能缩写，长度必须为7
                flag = false;
            }else{
                for (int i = 0, j =split.length-1 ; i < split.length; i++,j--) {
                    String s = split[i];
                    //出现其它字符
                    for (char c : s.toCharArray()) {
                        if(!Character.isDigit(c)){
                            flag = false;
                            break;
                        }
                    }
                    if(!flag){
                        break;
                    }
                    int num = s.length()==0 ? 0 : Integer.parseInt(s);

                    //开头不能为0,且数字不能大于255
                    if((i==0 && num==0 ) || num>255){
                        flag = false;
                        break;
                    }
                    //满足合法
                    long l = (long) num << (8 * j);
                    res = res | l;


                }
            }
            if(flag){
                System.out.println(res);
            }else{
                System.out.println(-1);
            }
        }

    }


}